<?php

require_once 'database.php';
require_once 'common.php';

session_start();

//Get information from the post
$strStoryName = $_POST['story_name'];
$strStoryDesc = $_POST['story_desc'];
$intIterationID = intval($_POST['iteration_id']);
//Insert new row into the database


$addStory = mysql_query("INSERT INTO story (story_name, story_desc, iteration_id) VALUES ('$strStoryName', '$strStoryDesc', (SELECT iteration_id from iteration WHERE iteration_id='$intIterationID'))")
   or die("Problem reading table: " . mysql_error());

$getStory =  mysql_query("SELECT * FROM story WHERE story_id = (SELECT MAX(story_id) FROM story)");

$row = mysql_fetch_array($getStory);
$id = $row['story_id'];
//Create the return object
$objReturn = array();
$objReturn['code'] = "SUCCESS";
$objReturn['story_id'] = $id;


header("content-type:application/json");
echo json_encode($objReturn);